unit NormalRoutines;

interface

uses
  VectorTypes;

type
  TGetNearestNormalFunc = function (Vector: TVector3f): Byte;

function GetNearestNormalRA2(Vector: TVector3f): Byte;
function GetNearestNormalTS(Vector: TVector3f): Byte;

implementation

uses
  Normals;

function GetNearestNormalRA2(Vector: TVector3f): Byte;
var
  i: Integer;
  DotProd, DotProdMax: Single;
begin
  DotProdMax := -1.0;
  for i := 0 to 240 do begin
    DotProd :=
      RA2Normals[i].X * Vector.X +
      RA2Normals[i].Y * Vector.Y +
      RA2Normals[i].Z * Vector.Z;
    if DotProd > DotProdMax then begin
      DotProdMax := DotProd;
      Result := i;
    end;
  end;
end;

function GetNearestNormalTS(Vector: TVector3f): Byte;
var
  i: Integer;
  DotProd, DotProdMax: Single;
begin
  DotProdMax := -1.0;
  for i := 0 to 35 do begin
    DotProd :=
      TSNormals[i].X * Vector.X +
      TSNormals[i].Y * Vector.Y +
      TSNormals[i].Z * Vector.Z;
    if DotProd > DotProdMax then begin
      DotProdMax := DotProd;
      Result := i;
    end;
  end;
end;
end.
